<template>
  <div>
      <page-header :title="'学院信息'+ type.Chinese" :content="'college ' + type.English" />
      <page-main>
         <search-bar>
            <el-form :model="search" size="small" label-width="120px">
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="名称">
                            <el-input v-model="search.name" placeholder="请输入名称，支持模糊查询" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="searchData()">筛选</el-button>
                        </el-form-item>
                    </el-col>
                    <auth value="permission.create">
                        <el-col :span="2">
                            <el-form-item>
                                <el-button type="primary" icon="el-icon-circle-plus-outline"><router-link to="/school_manager/collegeUpdate/add/*">新增</router-link></el-button>
                            </el-form-item>
                        </el-col>
                    </auth>
                </el-row>
            </el-form>
        </search-bar>
      </page-main>
      <page-main>
            <keep-alive>
                <TableList :tableKey="tableKey" :dataList="searchList" v-if="dataLists.length != 0" @CollageView='CollageView' @CollageEdit='CollageEdit' entityKey='Collage'></TableList>
            </keep-alive>
      </page-main>
  </div>
</template>

<script>
export default {
    name: 'collageList',
    data() {
        return {
            search: {
                name: '',
            },
            dataLists: [],
            searchList: [],
            tableKey: [{
                name: 'id',
                value: 'id'
            },{
                name: 'collegecode',
                value: '学院代码'
            },{
                name: 'collegename',
                value: '学院名称'
            }],
            type: {
                Chinese: '',
                English: ''
            }
        }
    },
    created() {
        this.$util.post('public/loadAllCollege').then(res => {
            this.dataLists = []
            this.searchList = []
            for(let i = 0; i < res.length; i++) {
                this.dataLists.push(res[i])
                this.searchList.push(res[i])
            }
        })
        if (this.$auth('permission.create')) {
            this.type.Chinese = '管理'
            this.type.English = 'manager'
        } else {
            this.type.Chinese = '视图'
            this.type.English = 'view'
        }
    },
    methods: {
        CollageView(row) {
            this.$router.push('/school_manager/collegeUpdate/view/' + row.id)
        },
        CollageEdit(row) {
            this.$router.push('/school_manager/collegeUpdate/edit/' + row.id)
        },
        searchData() {
            this.searchList = []
            if(this.search.name == '') {
                this.dataLists.forEach(item => {
                    this.searchList.push(item)
                })
            } else {
                this.dataLists.forEach((item) => {
                    if(item.collegename.indexOf(this.search.name) != -1) {
                        this.searchList.push(item)
                    }
                })
            }
        }
    }
}
</script>

